package cn.rdq.iknesssystem.controller;

import cn.rdq.api.po.Admin;
import cn.rdq.api.vo.LoginUser;
import cn.rdq.common.CommonResult;
import cn.rdq.iknesssystem.service.AdminService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Api
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public CommonResult login(@RequestBody LoginUser loginUser) {
        String token = UUID.randomUUID().toString();
        Map<String, Object> map = new HashMap<>();
        map.put("token", token);
        map.put("operator", adminService.login(loginUser));
        return CommonResult.successObj(map);
    }

    @GetMapping("/{id}")
    public CommonResult getAdminInfo(@PathVariable Long id) {
        Admin admin = adminService.getAdminInfoById(id);
        return CommonResult.successObj(admin);
    }

}
